/**
 * 说明：
 * 创建人：pluto
 * 创建时间：2018/8/9
 */

angular.module('app.request',[]).factory('request',function ($http, $q) {
    var httpAsPromise = function (options) {
        var deferred = $q.defer();
        $http(options).then(function (res) {
            if (res.status === 0) {
                deferred.resolve(res.data);
            } else {
                deferred.reject(res);
            }
        },function (error) {
            deferred.reject(error);
        });
        return deferred.promise;
    };
    return {
        get: function (url) {
            return httpAsPromise({
                method: 'GET',
                url: BASE_URL + url
            });
        },
        post: function (url, param) {
            return httpAsPromise({
                method: 'POST',
                url: BASE_URL + url,
                data: param
            });
        },
        put: function (url, param) {
            return httpAsPromise({
                method: 'PUT',
                url: BASE_URL + url,
                data: param
            });
        },
        delete: function (url, param) {
            return httpAsPromise({
                method: 'DELETE',
                url: BASE_URL + url,
                data: param
            });
        }
    }
});